﻿@model BannerView

<div>
    <div class="layui-container" style="margin-top:50px;margin-bottom:150px">
        <form class="layui-form" id="addForm" onsubmit="return false">
            <div class="layui-form-item">
                <label class="layui-form-label" style="font-weight:bolder;">标题</label>
                <div class="layui-input-block">
                    <input type="text" asp-for="Title" required lay-verify="title" autocomplete="off" class="layui-input">
                    <span asp-validation-for="Title" style="color: #F56C6C"></span>
                    @*<input type="text" id="Title" class="layui-input" placeholder="请输入标题" />*@
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="font-weight:bolder;">上传图片</label>
                <div class="layui-input-block">
                    <input type="file" id="uploadImg" asp-for="ImgUrl"/>
                    <span asp-validation-for="ImgUrl" style="color: #F56C6C"></span>
                    @*<input type="hidden" id="ImgUrl" />*@
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <img id="imgPhoto" class="layui-upload-img" style="width:180px; height:140px" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="font-weight:bolder;">跳转地址</label>
                <div class="layui-input-block">
                    <input type="text" asp-for="ToUrl" required lay-verify="title" autocomplete="off" class="layui-input">
                    <span asp-validation-for="ToUrl" style="color: #F56C6C"></span>
                    @*<input type="text" id="ToUrl" class="layui-input" placeholder="请输入跳转地址" />*@
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" id="subAdd" lay-submit lay-filter="subAdd"> 立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
@section Scripts{
    <script>
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer,
                $ = layui.$;

            //监听提交
            form.on('submit(subAdd)', function (data) {
                $.post("/Admin/Banner/Add", data.field, function (re) {
                    if (re.success) {
                        //发异步，把数据提交给
                        layer.alert(re.msg, { icon: 6 }, function () {
                            parent.layui.$("#subAdd").click();
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);

                            ////3,刷新父级页面
                            parent.location.reload();
                        });
                    } else {
                        layer.msg(re.msg);
                    }

                }, "json");

                return false;
            });

        });
    </script>
    @*<script>
        layui.use(['form', 'upload'], function () {
            var form = layui.form;
            var upload = layui.upload;
            var $ = layui.$;
            var layer = layui.layer;
            //upload.render({
            //    elem: "#uploadImg",
            //    url: "UploadPhoto",
            //    done: function (res) {
            //        if (res.success == true) {
            //            $("#ImgUrl").val(res.path);
            //            $("#imgPhoto").attr("src", "/" + res.path);
            //        }
            //    }
            //});
            form.on('submit(subAdd)', function () {
                $.ajax({
                    url: "AddDel",
                    method: "post",
                    dataType: "json",
                    data: {
                        Title: $("#Title").val(),
                        ImgUrl: $("#uploadImg").val(),
                        ToUrl: $("#ToUrl").val()
                    },
                    success: function (res) {
                        if (res.success == true) {
                            layer.msg(res.msg);
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);

                            parent.location.reload();
                        } else {
                            layer.msg(res.msg);
                        }
                    }
                });
                return false;
            })
        });
    </script>*@

    }
